import tinymce from 'tinymce';
export default (_self, h) => {
  let id= 'vue-tinymce-'+Date.now();
  let tinymceEditer= [
    h("textarea", {
      attrs: {
        type: "textarea",
        placeholder: _self.obj.placeholder || "这是一个富文本",
        value: _self.obj.value,
        maxlength: _self.obj.maxLength || 2000,
        id:id,
      }
    })
  ];
  //初始化富文本
  _self.$nextTick(() => {
      let vm = _self;
      tinymce.init({
          selector: '#'+id,
          branding: false,
          elementpath: false,
          height: 100,
          language: 'zh_CN.GB2312',
          menubar: 'edit insert view format table tools',
          plugins: [
              'advlist autolink lists link image charmap print preview hr anchor pagebreak imagetools',
              'searchreplace visualblocks visualchars code fullpage',
              'insertdatetime media nonbreaking save table contextmenu directionality',
              'emoticons paste textcolor colorpicker textpattern imagetools codesample'
          ],
          toolbar1: ' newnote print preview | undo redo | insert | styleselect | forecolor backcolor bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image emoticons media codesample',
          autosave_interval: '20s',
          image_advtab: true,
          table_default_styles: {
              width: '100%',
              borderCollapse: 'collapse'
          },
          setup: function (editor) {
              editor.on('change', function (e) {
                  if (!_self.obj.name) {
                      return false;
                  }
                  _self.obj.value = tinymce.get(id).getContent();
                  _self.$emit('handleChangeVal', _self.obj.value)
              });
          }
      });
  });
  return tinymceEditer;
};


export let tinymceConf = {
  // 对应数据库内类型
  type: 'tinymce',
  // 是否可配置
  config: true,
  // 控件左侧label内容
  label: '富文本',
  placeholder: '',
  // 是否显示行内元素
  // inlineBlock: false,
  // 最大长度
  maxLength: 2000,
  // 是否必填
  rules:{require: true},
  // 文本域行高 
  // maxRows: 2000,
  // 绑定的值
  value: "",
  // 表单name
  name: '',
  // 验证错误提示信息
  ruleError: '该字段不能为空',
  // 是否关联字段
  relation: false,
  // 关联字段name
  relation_name: '',
  // 关联字段value
  relation_value: '',
  // 是否被渲染
  visibility: true
}
